using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PaintDotNet.Web.Data;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

namespace WebPaint
{
    public partial class getThumbnail : System.Web.UI.Page
    {
        string user;
        string imageId;
        imageType type;

        public getThumbnail()
        {
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            user = Request.Params["userId"];
            if (Session.SessionID == Request.Params["userId"])
            {
                imageId = Request.Params["id"];
                int intType = Convert.ToInt32(Request.Params["type"]);
                type = util.convertIntToImageType(intType);

                Bitmap imagen = new Bitmap(util.getUserImage(user, imageId, type, true));
                //Cuidado GIFs, mirar Paint.NET
                Graphics grphcs = Graphics.FromImage(imagen);

                grphcs.DrawString(user,
                    new Font("Arial", 20, FontStyle.Bold), Brushes.Black, new PointF(0, 0));
                //imagen.GetThumbnailImage(75, 75,);

                imagen.Save(Response.OutputStream, ImageFormat.Jpeg);
            }
            else
            {
                Response.ContentType = "image/jpg";
                byte[] _bytes = new byte[1];
                _bytes[0] = 0;
                Response.OutputStream.Write(_bytes, 0, 0);

            }
        }        
    }
}
